var DEFAULT_CRM_SERVER = "devvm";
var DEFAULT_CRM_ORGANIZATION = "devcrm";
var DEFAULT_CRM_USER = "";
var DEFAULT_CRM_PASSWORD = "";
var DEFAULT_TIMER_INTERVAL = 300

//////////////////////////////////////////////////////

var CRM_SERVER = "";
var CRM_USER = "";
var CRM_PASSWORD = "";
var CRM_ORGANIZATION = "";

var SHOW_TASK = true;
var SHOW_FAX = true;
var SHOW_EMAIL = true;
var SHOW_PHONECALL = true;
var SHOW_APPOINTMENT = true;
var SHOW_LETTER = true;
var SHOW_SERVICEAPPOINTMENT = true;
var SHOW_CAMPAIGNRESPONSE = true;
var SHOW_CAMPAIGNACTIVITY = true;

var SORTBY = "";
var TIMER_INTERVAL = "";

function confInit() {
    if (CRM_SERVER == "") {
        CRM_SERVER = DEFAULT_CRM_SERVER;
        System.Gadget.Settings.write("CRM_SERVER", CRM_SERVER);
    }
    if (CRM_USER == "") {
        CRM_USER = DEFAULT_CRM_USER;
        System.Gadget.Settings.write("CRM_USER", CRM_USER);
    }
    if (CRM_PASSWORD == "") {
        CRM_PASSWORD = DEFAULT_CRM_PASSWORD;
        System.Gadget.Settings.write("CRM_PASSWORD", CRM_PASSWORD);
    }
    if (CRM_ORGANIZATION == "") {
        CRM_ORGANIZATION = DEFAULT_CRM_ORGANIZATION;
        System.Gadget.Settings.write("CRM_ORGANIZATION", CRM_ORGANIZATION);
    }    
    if (TIMER_INTERVAL == "") {
        TIMER_INTERVAL = DEFAULT_TIMER_INTERVAL;
        System.Gadget.Settings.write("TIMER_INTERVAL", TIMER_INTERVAL);
    }
    if (SORTBY == "") {
        SORTBY = "scheduledend";
        System.Gadget.Settings.write("SORTBY", SORTBY);
    }    
}

function confLoad() {
    CRM_SERVER = System.Gadget.Settings.read("CRM_SERVER");
    CRM_USER = System.Gadget.Settings.read("CRM_USER");
    CRM_PASSWORD = System.Gadget.Settings.read("CRM_PASSWORD");
    CRM_ORGANIZATION = System.Gadget.Settings.read("CRM_ORGANIZATION");

    if (System.Gadget.Settings.read("SHOW_TASK") == "false") SHOW_TASK = false; else SHOW_TASK = true;
    if (System.Gadget.Settings.read("SHOW_FAX") == "false") SHOW_FAX = false; else SHOW_FAX = true;
    if (System.Gadget.Settings.read("SHOW_EMAIL") == "false") SHOW_EMAIL = false; else SHOW_EMAIL = true;
    if (System.Gadget.Settings.read("SHOW_PHONECALL") == "false") SHOW_PHONECALL = false; else SHOW_PHONECALL = true;
    if (System.Gadget.Settings.read("SHOW_APPOINTMENT") == "false") SHOW_APPOINTMENT = false; else SHOW_APPOINTMENT = true;
    if (System.Gadget.Settings.read("SHOW_LETTER") == "false") SHOW_LETTER = false; else SHOW_LETTER = true;
    if (System.Gadget.Settings.read("SHOW_SERVICEAPPOINTMENT") == "false") SHOW_SERVICEAPPOINTMENT = false; else SHOW_SERVICEAPPOINTMENT = true;
    if (System.Gadget.Settings.read("SHOW_CAMPAIGNRESPONSE") == "false") SHOW_CAMPAIGNRESPONSE = false; else SHOW_CAMPAIGNRESPONSE = true;
    if (System.Gadget.Settings.read("SHOW_CAMPAIGNACTIVITY") == "false") SHOW_CAMPAIGNACTIVITY = false; else SHOW_CAMPAIGNACTIVITY = true;

    SORTBY = System.Gadget.Settings.read("SORTBY");
    TIMER_INTERVAL = System.Gadget.Settings.read("TIMER_INTERVAL");
}

function confSave() {
    System.Gadget.Settings.write("CRM_SERVER", CRM_SERVER);
    System.Gadget.Settings.write("CRM_USER", CRM_USER);
    System.Gadget.Settings.write("CRM_PASSWORD", CRM_PASSWORD);
    System.Gadget.Settings.write("CRM_ORGANIZATION", CRM_ORGANIZATION);

    System.Gadget.Settings.write("SHOW_TASK", SHOW_TASK.toString());
    System.Gadget.Settings.write("SHOW_FAX", SHOW_FAX.toString());
    System.Gadget.Settings.write("SHOW_EMAIL", SHOW_EMAIL.toString());
    System.Gadget.Settings.write("SHOW_PHONECALL", SHOW_PHONECALL.toString());
    System.Gadget.Settings.write("SHOW_APPOINTMENT", SHOW_APPOINTMENT.toString());
    System.Gadget.Settings.write("SHOW_LETTER", SHOW_LETTER.toString());
    System.Gadget.Settings.write("SHOW_SERVICEAPPOINTMENT", SHOW_SERVICEAPPOINTMENT.toString());
    System.Gadget.Settings.write("SHOW_CAMPAIGNRESPONSE", SHOW_CAMPAIGNRESPONSE.toString());
    System.Gadget.Settings.write("SHOW_CAMPAIGNACTIVITY", SHOW_CAMPAIGNACTIVITY.toString());

    System.Gadget.Settings.write("SORTBY", SORTBY);
    System.Gadget.Settings.write("TIMER_INTERVAL", TIMER_INTERVAL);
}